package com.tg.app.activity.device.ui.cameraview;

import com.tange.base.toolkit.TGThreadPool;

public class PlaybackRunnableHelper {
    public interface RunnableListener{
        void timeRuleJumpNextFunc();
        void autoScrollFunc();
    }

    public void removeTimeRuleViewJumpNextRunnable(){
        TGThreadPool.getMainHandler().removeCallbacks(timeRuleViewJumpNextRunnable);
    }

    public void removeAutoScrollRunnable(){
        TGThreadPool.getMainHandler().removeCallbacks(autoScrollRunnable);
    }

    public void setRunnableListener(RunnableListener runnableListener) {
        mRunnableListener = runnableListener;
    }

    public void postDelayedForAutoScrollRunnable(long delayMillis){
        if (delayMillis == 0){
            TGThreadPool.getMainHandler().post(timeRuleViewJumpNextRunnable);
        }else{
            TGThreadPool.getMainHandler().postDelayed(autoScrollRunnable, delayMillis);
        }

    }

    public void postDelayedForTimeRuleViewJumpNextRunnable(long delayMillis){
        if (delayMillis == 0){
            TGThreadPool.getMainHandler().post(timeRuleViewJumpNextRunnable);
        }else{
            TGThreadPool.getMainHandler().postDelayed(timeRuleViewJumpNextRunnable, delayMillis);
        }
    }


    private RunnableListener mRunnableListener;
    private Runnable timeRuleViewJumpNextRunnable = new Runnable() {
        @Override
        public void run() {
            removeAutoScrollRunnable();
            if (mRunnableListener != null){
                mRunnableListener.timeRuleJumpNextFunc();
            }
        }
    };

    private Runnable autoScrollRunnable = new Runnable() {
        @Override
        public void run() {
            if (mRunnableListener != null){
                mRunnableListener.autoScrollFunc();
            }
        }
    };
}
